﻿@namespace MudBlazor
@typeparam T
@inherits MudDebouncedInput<T>

<CascadingValue Name="SubscribeToParentForm" Value="@SubscribeToParentForm" IsFixed="true">
    <MudInputControl Label="@Label"
                     Variant="@Variant"
                     HelperId="@GetHelperId()"
                     HelperText="@HelperText"
                     HelperTextOnFocus="@HelperTextOnFocus"
                     CounterText="@GetCounterText()"
                     FullWidth="@FullWidth"
                     Class="@Classname"
                     Error="@HasErrors"
                     ErrorId="@ErrorId"
                     ErrorText="@GetErrorText()"
                     Disabled="@GetDisabledState()"
                     Margin="@Margin"
                     Required="@Required"
                     ForId="@InputElementId">
        <InputContent>
            <CascadingValue Name="SubscribeToParentForm" Value="false" IsFixed="true">
                @if (_mask == null)
                {
                    <MudInput T="string"
                              @ref="InputReference"
                              @attributes="UserAttributes"
                              Label="@Label"
                              InputType="@InputType"
                              InputMode="@InputMode"
                              Lines="@Lines"
                              MaxLines="@MaxLines"
                              AutoGrow="@AutoGrow"
                              Style="@Style"
                              Variant="@Variant"
                              Typo="@Typo"
                              TextUpdateSuppression="@TextUpdateSuppression"
                              Value="@Text"
                              ValueChanged="(s) => SetTextAsync(s)"
                              Placeholder="@Placeholder"
                              Disabled=@GetDisabledState()
                              Underline="@Underline"
                              ReadOnly="@GetReadOnlyState()"
                              MaxLength="@MaxLength"
                              Adornment="@Adornment"
                              AdornmentText="@AdornmentText"
                              AdornmentIcon="@AdornmentIcon"
                              AdornmentColor="@AdornmentColor"
                              AdornmentAriaLabel="@AdornmentAriaLabel"
                              IconSize="@IconSize"
                              OnAdornmentClick="@OnAdornmentClick"
                              Error="@Error"
                              ErrorId="@ErrorId"
                              HelperId="@GetHelperId()"
                              HelperText="@HelperText"
                              Immediate="@Immediate"
                              Margin="@Margin"
                              OnBlur="@OnBlurredAsync"
                              OnKeyDown="@InvokeKeyDownAsync"
                              OnInternalInputChanged="OnChange"
                              OnKeyUp="@InvokeKeyUpAsync"
                              KeyDownPreventDefault="KeyDownPreventDefault"
                              KeyUpPreventDefault="KeyUpPreventDefault"
                              HideSpinButtons="true"
                              Clearable="@Clearable"
                              ClearIcon="@ClearIcon"
                              OnClearButtonClick="@OnClearButtonClick"
                              Pattern="@Pattern"
                              ShrinkLabel="@ShrinkLabel"
                              InputId="@InputElementId"
                              Required="@Required"/>
                }
                else
                {
                    <MudMask @ref="_maskReference"
                             @attributes="UserAttributes"
                             Label="@Label"
                             Mask="@_mask"
                             InputType="@InputType"
                             InputMode="@InputMode"
                             Lines="@Lines"
                             Style="@Style"
                             Variant="@Variant"
                             Typo="Typo"
                             TextUpdateSuppression="@TextUpdateSuppression"
                             Value="@Text"
                             ValueChanged="OnMaskedValueChanged"
                             Placeholder="@Placeholder"
                             Disabled=@GetDisabledState()
                             Underline="@Underline"
                             ReadOnly="@GetReadOnlyState()"
                             MaxLength="@MaxLength"
                             Adornment="@Adornment"
                             AdornmentText="@AdornmentText"
                             AdornmentIcon="@AdornmentIcon"
                             AdornmentColor="@AdornmentColor"
                             AdornmentAriaLabel="@AdornmentAriaLabel"
                             IconSize="@IconSize"
                             OnAdornmentClick="@OnAdornmentClick"
                             Error="@Error"
                             ErrorId="@ErrorId"
                             HelperId="@HelperId"
                             HelperText="@HelperText"
                             Immediate="@Immediate"
                             Margin="@Margin" OnBlur="@OnBlurredAsync"
                             Clearable="@Clearable"
                             ClearIcon="@ClearIcon"
                             OnClearButtonClick="@OnClearButtonClick"
                             InputId="@InputElementId"
                             Required="@Required"/>
                }
            </CascadingValue>
        </InputContent>
    </MudInputControl>
</CascadingValue>
